﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Collections.Specialized;

public partial class CreateTableScript : System.Web.UI.Page
{
    ArrayList al = new ArrayList();
    ServerConnection conn = new ServerConnection();
    Server server;
    Database db;

    protected void Page_Load(object sender, EventArgs e)
    {

        conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString;
        server = new Server(conn);
        db = server.Databases["Northwind"];

        TableCollection tc = db.Tables;
        
        this.DropDownList1.DataSource = tc;

        this.DropDownList1.DataBind();
       
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Write(((DropDownList)sender).SelectedValue);
         //Microsoft.SqlServer.Management.Smo.Table tb=db.Tables[((DropDownList)sender).SelectedItem.Text];
         //StringCollection sc = tb.Script();
         //string[] script = new string[sc.Count];
         //sc.CopyTo(script, 0);
         //this.TextBox1.Text = sc[2];
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Response.Write(((DropDownList)sender).SelectedValue);
        Microsoft.SqlServer.Management.Smo.Table tb = db.Tables["Orders"];
        StringCollection sc = tb.Script();
        string[] script = new string[sc.Count];
        sc.CopyTo(script, 0);
        this.TextBox1.Text = sc[2];
    }
}
